package com.hwtx.form.persistence;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hwtx.form.domain.repo.RoleUserRepo;
import com.hwtx.form.domain.vo.UserRole;
import com.hwtx.form.persistence.mapper.SysRoleUserMapper;
import io.geekidea.boot.system.entity.SysMenu;
import io.geekidea.boot.system.entity.SysRoleUser;
import io.geekidea.boot.system.mapper.SysMenuMapper;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@Service
public class RoleUserRepoImpl extends ServiceImpl<SysRoleUserMapper, SysRoleUser> implements RoleUserRepo {

    @Resource
    private SysRoleUserMapper sysRoleUserMapper;
    @Resource
    private SysMenuMapper sysMenuMapper;

    @Override
    public List<UserRole> getUserRoles(List<Long> userIds) {
        return sysRoleUserMapper.getUserRoles(userIds);
    }

    @Override
    public List<String> getResourceCodeByUserId(Long userId, List<Integer> types) {
        return sysMenuMapper.getResourceCodeAndIdByUserRole(userId, types).stream().map(SysMenu::getCode).collect(Collectors.toList());
    }
}
